﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using org.Alexander.EDAS;

namespace EdasServer
{
    class Program
    {
        static void Main(string[] args)
        {
            Acceptor acp = new Acceptor(8888);
            acp.OnError = (ex, str) =>
            {
                //TO DO:To handle listenner's error
            };
            acp.Accepted = (sock,id,buffersize) =>
            {
                AsyncSocket sk = new AsyncSocket(sock, buffersize);
                sk.ID = id;
                sk.OnError += new Action<Exception, string>(sk_OnError);
                sk.Disconnected += new Action<long>(sk_Disconnected);
                TokenProcessor Proc = new TokenProcessor(0x0A);
                Proc.OnToken += new Action<IWorkingSocket, byte[]>(Proc_OnLine);
                sk.Processor = Proc;
                sk.WaitReceive();
            };
            acp.WaitAsyncAccept();
            Console.ReadKey();
        }
        static void sk_Disconnected(long obj)
        {
            //TO DO:To handle disconnect event
        }
        static void Proc_OnLine(IWorkingSocket arg1, byte[] arg2)
        {
            arg1.SendToQueue(arg2);
        }
        static void sk_OnError(Exception arg1, string arg2)
        {
            //TO DO:Process errors
        }
    }
}
